package com.zhny.project.txt.calculation.controller;

import com.zhny.common.utils.poi.ExcelUtil;
import com.zhny.framework.aspectj.lang.annotation.Log;
import com.zhny.framework.aspectj.lang.enums.BusinessType;
import com.zhny.framework.web.controller.BaseController;
import com.zhny.framework.web.domain.AjaxResult;
import com.zhny.framework.web.page.TableDataInfo;
import com.zhny.project.txt.calculation.domain.TxtCalculation;
import com.zhny.project.txt.calculation.service.ITxtCalculationService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * txt分析计算记录Controller
 *
 * @author yanqun
 * @date 2020-01-18
 */
@Controller
@RequestMapping("/txt/calculation")
public class TxtCalculationController extends BaseController
{
    private String prefix = "txt/calculation";

    @Autowired
    private ITxtCalculationService txtCalculationService;

    @RequiresPermissions("txt:calculation:view")
    @GetMapping()
    public String calculation()
    {
        return prefix + "/calculation";
    }

    /**
     * 查询txt分析计算记录列表
     */
    @RequiresPermissions("txt:calculation:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TxtCalculation txtCalculation)
    {
        startPage();
        List<TxtCalculation> list = txtCalculationService.selectTxtCalculationList(txtCalculation);
        return getDataTable(list);
    }

    /**
     * 导出txt分析计算记录列表
     */
    @RequiresPermissions("txt:calculation:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TxtCalculation txtCalculation)
    {
        List<TxtCalculation> list = txtCalculationService.selectTxtCalculationList(txtCalculation);
        ExcelUtil<TxtCalculation> util = new ExcelUtil<TxtCalculation>(TxtCalculation.class);
        return util.exportExcel(list, "calculation");
    }

    /**
     * 新增txt分析计算记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存txt分析计算记录
     */
    @RequiresPermissions("txt:calculation:add")
    @Log(title = "txt分析计算记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TxtCalculation txtCalculation)
    {
        return toAjax(txtCalculationService.insertTxtCalculation(txtCalculation));
    }

    /**
     * 修改txt分析计算记录
     */
    @GetMapping("/edit/{calculationKey}")
    public String edit(@PathVariable("calculationKey") String calculationKey, ModelMap mmap)
    {
        TxtCalculation txtCalculation = txtCalculationService.selectTxtCalculationById(calculationKey);
        mmap.put("txtCalculation", txtCalculation);
        return prefix + "/edit";
    }

    /**
     * 修改保存txt分析计算记录
     */
    @RequiresPermissions("txt:calculation:edit")
    @Log(title = "txt分析计算记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TxtCalculation txtCalculation)
    {
        return toAjax(txtCalculationService.updateTxtCalculation(txtCalculation));
    }

    /**
     * 删除txt分析计算记录
     */
    @RequiresPermissions("txt:calculation:remove")
    @Log(title = "txt分析计算记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(txtCalculationService.deleteTxtCalculationByIds(ids));
    }
}
